package cn.iocoder.yudao.module.wine.controller.admin.premiumrecord;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.admin.premiumrecord.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.premiumrecord.PremiumRecordDO;
import cn.iocoder.yudao.module.wine.service.premiumrecord.PremiumRecordService;

@Tag(name = "管理后台 - 保费记录")
@RestController
@RequestMapping("/wine/premium-record")
@Validated
public class PremiumRecordController {

    @Resource
    private PremiumRecordService premiumRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建保费记录")
    @PreAuthorize("@ss.hasPermission('wine:premium-record:create')")
    public CommonResult<Long> createPremiumRecord(@Valid @RequestBody PremiumRecordSaveReqVO createReqVO) {
        return success(premiumRecordService.createPremiumRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新保费记录")
    @PreAuthorize("@ss.hasPermission('wine:premium-record:update')")
    public CommonResult<Boolean> updatePremiumRecord(@Valid @RequestBody PremiumRecordSaveReqVO updateReqVO) {
        premiumRecordService.updatePremiumRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除保费记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wine:premium-record:delete')")
    public CommonResult<Boolean> deletePremiumRecord(@RequestParam("id") Long id) {
        premiumRecordService.deletePremiumRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得保费记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wine:premium-record:query')")
    public CommonResult<PremiumRecordRespVO> getPremiumRecord(@RequestParam("id") Long id) {
        PremiumRecordDO premiumRecord = premiumRecordService.getPremiumRecord(id);
        return success(BeanUtils.toBean(premiumRecord, PremiumRecordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得保费记录分页")
    @PreAuthorize("@ss.hasPermission('wine:premium-record:query')")
    public CommonResult<PageResult<PremiumRecordRespVO>> getPremiumRecordPage(@Valid PremiumRecordPageReqVO pageReqVO) {
        PageResult<PremiumRecordRespVO> pageResult = premiumRecordService.getPremiumRecordPage(pageReqVO);
        return success(pageResult);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出保费记录 Excel")
//    @PreAuthorize("@ss.hasPermission('wine:premium-record:export')")
//    @OperateLog(type = EXPORT)
//    public void exportPremiumRecordExcel(@Valid PremiumRecordPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<PremiumRecordDO> list = premiumRecordService.getPremiumRecordPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "保费记录.xls", "数据", PremiumRecordRespVO.class,
//                        BeanUtils.toBean(list, PremiumRecordRespVO.class));
//    }

}
